#pragma once
/*
 * Created by: Mark Lavrynenko
 * Email:	MarkLavrinenko@gmail.com
 * Project:	  Huffman
*/

#include  "HuffmanTreeNode.h"
#include <stdint.h>
#include <vector>

class FrequencyTable;
class IHTreeCallBack;
class CodingTable;

enum DFSDirection
{
	TurnLeft,
	TurnRight,			
	Rise,					// go to parent
	None					// it's root
};

typedef void (*CallBack)(HuffmanTreeNode* node, DFSDirection dir);

using std::vector;

class HTree
{
public:
	HTree(HuffmanTreeNode* root);
	~HTree(void);
	void archiveByte(uint8_t byte);
	void unArchivebyte(uint8_t byte);
	CodingTable* createTable();
	IHTreeCallBack* myDelegate;
private:
	HuffmanTreeNode* root;
	// state of the finite state machine
	HuffmanTreeNode* state;
	// bad design with static
	static vector<char> path;
	void dfs(HuffmanTreeNode* ver, CallBack helper, DFSDirection dir = DFSDirection::None);
	static void codingTableBuilder(HuffmanTreeNode* node, DFSDirection dir);
	static CodingTable* codingTable;
};
